package reflection;

import java.lang.reflect.Field;

public class ReflecAccessProperty {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException, InstantiationException {
        Class<?> aClass = Class.forName("reflection.Student");
        Object o = aClass.newInstance();
        Field age = aClass.getField("age");
        age.set(o,88);

        Field name = aClass.getDeclaredField("name");
        name.setAccessible(true);//爆破
        name.set(null,"嘤嘤嘤");//因为是静态属性 可以用空
    }
}
class Student{
    public int age;
    private static String name;

    public Student(){

    }

    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                '}';
    }
}
